package com.testAll;

import com.alibaba.fastjson.JSON;
import com.core.jdbc.SqlHelper;
import com.core.util.CommonUtil;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author liujian
 * @email v_vjiannliu@tencent.com
 * @date 2022/3/15 15:30
 */
public class testComparePub {
    public static void main(String[] args) throws Exception {
        compare();
    }

    public static void compare() throws Exception {
        String sql = "SELECT * from pub;";
        List<Map<String, Object>> list = SqlHelper.queryMapList(sql, new HashMap<>());
        Map<String, String> dcacheMap = new HashMap<>();
        Map<String, String> dataAttaMap = new HashMap<>();
        for (Map<String, Object> map : list) {
            String data = CommonUtil.toString(map.get("userid"));
            String userid = data.split("\\|")[0];
            dataAttaMap.put(userid, data);
        }

        String dcacheJson = CommonUtil.readJsonFile("C:\\Users\\v_vjiannliu\\Desktop\\useraccunew\\data\\dcache.json");

        List<String> jsonList = JSON.parseArray(dcacheJson, String.class);

        for (String json : jsonList) {
            String userid = Arrays.asList(json.split("\\|")).get(0);
            dcacheMap.put(userid, json);

        }


        //
        List<String> result = new LinkedList<>();
        dcacheMap.forEach((k, v) -> {
            if (dataAttaMap.get(k) == null) {
                result.add(v);
            }
        });
        String str = String.format("%s %s %s 3月8日9日差异的数据%s:", list.size(), jsonList.size(),
                dataAttaMap.keySet().size(), result.size());

        String str2 = String.format("3月8日9日差异的数据(主库多出的userid数量)%s:", result.size());
        System.out.println(str2);
        System.out.println(JSON.toJSONString(result));

    }

    public static void test2() {
        String json = CommonUtil.readJsonFile("C:\\Users\\v_vjiannliu\\Desktop\\useraccunew\\data\\pub.json");
        Map<String, Object> jsonResult = JSON.parseObject(json);
        //System.out.println(jsonResult);
        List<Map<String, Object>> list = (List<Map<String, Object>>) jsonResult.get("RECORDS");
        System.out.println(list);
    }


}
